package com.dxl.service.sysprop;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dxl.common.model.Page;
import com.dxl.common.model.RespData;
import com.dxl.common.utils.Utils;
import com.dxl.dao.sysprop.SysPropDao;
import com.dxl.entity.sysprop.SysProp;
import com.dxl.service.common.BaseService;

@Service
@Transactional
public class SysPropService extends BaseService {
	private static final Logger LOG = Logger.getLogger(SysPropService.class);
	@Autowired
	private SysPropDao sysPropDao;
	
	public RespData save(SysProp sysProp) {
		SysProp srcSysProp;
		if (Utils.isNotBlank(sysProp.getId())) {
			srcSysProp = this.get(SysProp.class, sysProp.getId());
			srcSysProp.setOrderValue(sysProp.getOrderValue());
			srcSysProp.setPropKey(sysProp.getPropKey());
			srcSysProp.setPropValue(sysProp.getPropValue());
			srcSysProp.setRemark(sysProp.getRemark());
			srcSysProp.setState(sysProp.getState());
		} else {
			srcSysProp = sysProp;
		}
		super.save(srcSysProp);
		return RespData.instance(RespData.SUCCESS, srcSysProp.getId());
	}
	
	public RespData del(String[] ids) {
		if (Utils.isEmpty(ids)) {
			return RespData.instance(RespData.SUCCESS);
		} else {
			try {
				this.del(SysProp.class, ids);
				return RespData.instance(RespData.SUCCESS);
			} catch (Exception e) {
				LOG.error(e.getMessage(), e);
				return RespData.instance(RespData.FAIL);
			}
		}
	}
	
	public RespData state(String[] ids, Integer state) {
		if (Utils.isEmpty(ids)) {
			return RespData.instance(RespData.SUCCESS);
		} else {
			try {
				super.state(SysProp.class, ids, state);
				return RespData.instance(RespData.SUCCESS);
			} catch (Exception e) {
				LOG.error(e.getMessage(), e);
				return RespData.instance(RespData.FAIL);
			}
		}
	}
	
	public Page<SysProp> list(String keyword, Integer state, Integer page, Integer rows) {
		return sysPropDao.list(keyword, state, page, rows);
	}
}
